function varargout = htk_tools(varargin)

%  __  __                            _   _       
% |  \/  |                          | | | |      
% | \  / | __ _ _ __ __ _ _   _  ___| |_| |_ ___ 
% | |\/| |/ _` | '__/ _` | | | |/ _ \ __| __/ _ \
% | |  | | (_| | | | (_| | |_| |  __/ |_| ||  __/
% |_|  |_|\__,_|_|  \__, |\__,_|\___|\__|\__\___|
%                      | |                       
%                      |_|                       
%  _    _       _                    _ _         
% | |  | |     (_)                  (_) |        
% | |  | |_ __  ___   _____ _ __ ___ _| |_ _   _ 
% | |  | | '_ \| \ \ / / _ \ '__/ __| | __| | | |
% | |__| | | | | |\ V /  __/ |  \__ \ | |_| |_| |
%  \____/|_| |_|_| \_/ \___|_|  |___/_|\__|\__, |
%                                           __/ |
%                                          |___/ 
% Last Modified by Corey Bost for Marquette University's
% Speech and Signal Processing Lab
%
%This file is part of the Marquette Univeristy Speech Recognition Toolkit.
%The main purpose of this module is to present all of the secondary modules
%in an easy to manage way. This m-file itself does nothing but call other
%files.

%Copyright 2009

%HTK_TOOLS M-file for htk_tools.fig
%      HTK_TOOLS, by itself, creates a new HTK_TOOLS or raises the existing
%      singleton*.
%
%      H = HTK_TOOLS returns the handle to a new HTK_TOOLS or the handle to
%      the existing singleton*.
%
%      HTK_TOOLS('Property','Value',...) creates a new HTK_TOOLS using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to htk_tools_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      HTK_TOOLS('CALLBACK') and HTK_TOOLS('CALLBACK',hObject,...) call the
%      local function named CALLBACK in HTK_TOOLS.M with the given input
%      arguments.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help_menu htk_tools

% Last Modified by GUIDE v2.5 06-Aug-2009 10:53:55

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @htk_tools_OpeningFcn, ...
                   'gui_OutputFcn',  @htk_tools_OutputFcn, ...
                   'gui_LayoutFcn',  [], ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
   gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% Look, comments! %

% --- Executes just before htk_tools is made visible.

function htk_tools_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

% Choose default command line output for htk_tools
handles.output = hObject;
guidata(hObject, handles);
global main_dir; 
main_dir = strrep(which('htk_tools_OpeningFcn'),'\htk_tools.m','');
addpath(main_dir);
% Update handles structure
guidata(hObject, handles);
set(gcf,'CloseRequestFcn',@my_closefcn);
guidata(hObject, handles);
if strcmp(get(hObject,'Visible'),'off')
    initialize_gui(hObject, handles);
end
if exist([main_dir '/Data/Result_allcalltype'], 'dir') ~=7
    mkdir([main_dir '/Data/Result_allcalltype']);
end
    
if ~exist([main_dir '/Data/HParse.exe'],'file') || ~exist([main_dir '/Data/HCopy.exe'],'file')...
        || ~exist([main_dir '/Data/HVite.exe'],'file') || ~exist([main_dir '/Data/HResults.exe'],'file')...
        || ~exist([main_dir '/Data/HCompV.exe'],'file')|| ~exist([main_dir '/Data/HERest.exe'],'file')...
        || ~exist([main_dir '/Data/HHEd.exe'],'file')
    set(handles.data_preparation,'enable','off');
    set(handles.training,'enable','off');   
    set(handles.run_recognition,'enable','off');
    choice = questdlg(sprintf(['It appears that the HTK Tools could not be found, '...
        'and as a result all modules utilizing them have been disabled. '...
        'Please make sure that they are in executable form (.exe), and that '...
        'they are in the "/Data" directory.\n If you do not have them, or they '...
        'are not in executable form, please see the help documentation.']),...
        'HTK Tools not found','Help','Ok','Ok');
    switch choice,
        case 'Ok',
            return
        case 'Help',
            help_launch('gethtk');
    end
end


% UIWAIT makes htk_tools wait for user response (see UIRESUME)
% uiwait(handles.figure1);

function my_closefcn(hObject, eventdata, handles, varargin)
%Close function
selection = questdlg('Are you sure you want to quit?',...
    'Close Request Function',...
    'Yes','No','No');
switch selection,
    case 'Yes',
        delete(gcf)
    case 'No'
        return
end

% --- Outputs from this function are returned to the command line.
function varargout = htk_tools_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
try
varargout{1} = handles.output;
catch e
    warndlg(['There has been a minor error. To avoid this in the future, please'...
        ' start the program by running Run_Me.m or htk_tools.m.'])
end


% --- Executes on button press in create_category.
function create_category_Callback(hObject, eventdata, handles)
% hObject    handle to create_category (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% delete(gcf);
create_category


% --- Executes on button press in configuration.
function configuration_Callback(hObject, eventdata, handles)
% hObject    handle to configuration (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% delete(gcf);
config


% --- Executes on button press in data_preparation.
function data_preparation_Callback(hObject, eventdata, handles)
% hObject    handle to data_preparation (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% delete(gcf);
data_prepare


% --- Executes on button press in run_recognition.
function run_recognition_Callback(hObject, eventdata, handles)
% hObject    handle to run_recognition (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% delete(gcf);
run_recognition

% --- Executes on button press in training.
function training_Callback(hObject, eventdata, handles)
% hObject    handle to training (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% delete(gcf);
training


% --- Executes on button press in create_label.
function create_label_Callback(hObject, eventdata, handles)
% hObject    handle to create_label (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% delete(gcf);
create_label


% --------------------------------------------------------------------
function file_menu_Callback(hObject, eventdata, handles)
% hObject    handle to file_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function help_menu_Callback(hObject, eventdata, handles)
% hObject    handle to help_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function exit_Callback(hObject, eventdata, handles)
% hObject    handle to exit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
my_closefcn(hObject,eventdata,handles)


% --------------------------------------------------------------------
function about_us_Callback(hObject, eventdata, handles)
% hObject    handle to about_us (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
about_us;

% --------------------------------------------------------------------
function help_Callback(hObject, eventdata, handles)
% hObject    handle to help (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%{
helpdlg(sprintf(['"Create Category" is used to create and edit categories of data files.\n\n'...
    '"Create Label" is used to make the Master Label File.\n\n'...
    '"Configuration" is used to specify the parameters of the config file. This module also creates the config and proto files which will be used later in the Recognition.\n\n'...
    '"Data Preparation" is used to do the file conversions from sound format to .mfc file extension.\n\n'...
    '"Training" is used to train the program.\n\n'...
    '"Run Recognition" is where the actual recognition happens.']),'Using the Recognition Toolkit');
%}
help_launch('main');

% --- Executes on button press in long_data.
function long_data_Callback(hObject, eventdata, handles)
% hObject    handle to long_data (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% delete(gcf);
Long_Data_Labeling;

function initialize_gui(fig_handle, handles)

axes(handles.axes1);
axis off;
set(handles.training,'string', '<html><center>Training and<br> Cross-Validation');
set(handles.long_data,'string','<html><center>Long Data Labeling<br>and File Conversion');
logo = imread('background.bmp');
imshow(logo);
pause(2)
